/*
 * Copyright 2017-2020 吴学文 and java110 team.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.java110.mall.cart.api;

import com.alibaba.fastjson.JSONObject;
import com.java110.mall.cart.bmo.cart.ICartBMO;
import com.java110.mall.cart.storeOrderEngine.StoreOrderEngine;
import com.java110.po.storeOrder.StoreOrderPo;
import com.java110.utils.util.Assert;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 购物车接口类
 *
 * @desc add by 吴学文 14:23
 */
@RestController
@RequestMapping(value = "/cart")
public class CartApi {

    @Autowired
    private ICartBMO cartBMOImpl;

    @Autowired
    private StoreOrderEngine storeOrderEngine;

    /**
     * 商户统一下单
     *
     * @param reqJson
     * @return
     * @serviceCode /cart/unifiedOrder
     * @path /app/cart/unifiedOrder
     */
//    @RequestMapping(value = "/unifiedOrder", method = RequestMethod.POST)
//    public ResponseEntity<String> unifiedOrder(@RequestHeader(value = "app-id") String appId, @RequestBody JSONObject reqJson) {
//        reqJson.put("appId", appId);
//        StoreOrderPo storeOrderPo = storeOrderEngine.unifiedOrder(reqJson);
//
//        return ResultVo.createResponseEntity(ResultVo.CODE_OK, "成功", storeOrderPo);
//
//    }


    /**
     * 优惠卷赠送
     *
     * @param reqJson
     * @return
     * @serviceCode /cart/sendGoldCount
     * @path /app/cart/sendGoldCount
     */
    @RequestMapping(value = "/sendGoldCount", method = RequestMethod.POST)
    public ResponseEntity<String> sendGoldCount(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "goldCostMoney", "请求报文中未包含赠送数量");
        Assert.hasKeyAndValue(reqJson, "spId", "请求报文中未指定优惠卷");
        Assert.hasKeyAndValue(reqJson, "shopId", "请求报文中未包含商铺");
        Assert.hasKeyAndValue(reqJson, "vipId", "请求报文中未包含会员");

        return cartBMOImpl.saveSendGoldCount(reqJson);
    }

    /**
     * 停车优惠卷赠送
     *
     * @param reqJson
     * @return
     * @serviceCode /cart/saveSendParking
     * @path /app/cart/saveSendParking
     */
    @RequestMapping(value = "/saveSendParking", method = RequestMethod.POST)
    public ResponseEntity<String> saveSendParking(@RequestHeader(value = "store-id") String storeId,
                                                  @RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "licensePlate", "请求报文中未包含车牌号");
        Assert.hasKeyAndValue(reqJson, "giftsCostMoney", "请求报文中未包含赠送数量");
        Assert.hasKeyAndValue(reqJson, "spId", "请求报文中未指定优惠卷");
        Assert.hasKeyAndValue(reqJson, "shopId", "请求报文中未包含商铺");
        Assert.hasKeyAndValue(reqJson, "tel", "请求报文中未包含会员");


        return cartBMOImpl.saveSendParking(reqJson, storeId);
    }
}
